package com.java.base.exercise.funcationinterface;


import com.java.base.exercise.jvm.User;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
 * java 8 【predicate 数据判断函数案例的编写】
 */
public class PreciateFunction {

    public static List<User> filter(List<User> paramList, Predicate<User> predicate) {

        List<User> commonList = new ArrayList<>();
        paramList.forEach(s -> {
            if (predicate.test(s)) {
                commonList.add(s);
            }
        });

        return commonList;
    }

    public static void main(String[] args) {

        List<User> userList = new ArrayList<>();

        User user = new User();
        user.setName("张三");
        user.setAge(18);

        User user1 = new User();
        user1.setName("李四");
        user1.setAge(36);

        User user2 = new User();
        user2.setName("麻五");
        user2.setAge(28);

        userList.add(user);
        userList.add(user1);
        userList.add(user2);


        List<User> filterAfterResult = filter(userList, (s) -> s.getName().equals("李四"));

        System.out.println("打印条件过滤的结果：：" + filterAfterResult);


    }

}
